// pages/promotion/promotion.js
const api = require("../../request/api")
const request = require("../../request/request")
const util = require("../../utils/util")
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // tab相关数据
    title_list: [{name: "21:00开抢"},{name: "22:00开抢",},{name: "23:00开抢"}],
    chosen_index: 0,



    uid: 9,
    page: 1,
    page_size: 10,
    skill_list: [],
    day: '',
    hour: '',
    minute:'',
    second: '',
    exclusive_list: [],
    guess_list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.init_data()
    this.get_skill_list()
    // this.selectComponent("#promotion-good").countTime()
    this.get_goods_list()
    
  },
  get_goods_list() {
    let params = {
      page: this.data.page,
      pageSize: this.data.page_size,
      uid: this.data.uid 
    }
    request.post(api.goods_more, params).then(res=>{
      this.setData({
        exclusive_list: res,
        guess_list: res
      })
    })
  },
  go_back() {
    wx.navigateBack({
      delta: 1,
    })

  },
  // tab
  changing_tab(e) {
    this.setData({
      chosen_index: e.currentTarget.dataset.index
    })
  },

  go_detail_from_component(e) {
    let id = e.detail.currentTarget.dataset.id
    if (!id) {
      id = 10
    }
    wx.navigateTo({
      url: '/pages/good/detail?id=' + id,
    })
  },
  go_detail(e) {
    let id = e.currentTarget.dataset.id
    if (!id) {
      id = 10
    }
    wx.navigateTo({
      url: '/pages/good/detail?id=' + id + '&entrance=promotion',
    })
  },
  init_data() {
    this.setData({
      uid: util.getAppValue(App.globalData.uid),
    })
  },
  get_skill_list() {
    let params = {
      uid: this.data.uid,
      page: this.data.page,
      page_size: this.data.page_size,
    }
    util.showLoading('加载中')
    request.post(api.skilllist, params).then(res=>{
      util.hideLoading()
      this.setData({
        skill_list: res
      })
    })
  },

  cart_add(){
    util.showLoading("正在添加")
    let params = {
      // goods_num: this.data.cart_num,
      goods_id: this.data.goods_id,
      uid: this.data.uid
    }
    request.post(api.cart_add, params).then(res=>{
      this.setData({
        if_show_box:false
      })
      util.showToast("已加入购物车")
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})